package net.zjitc.servlet.product;

import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProduceServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/10/30.
 */
@WebServlet(name = "EditPageServlet",urlPatterns = "/editPageServlet")
public class EditPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   doGet(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String currentPage = request.getParameter("currentPage");
        Product p = new Product();
        try {
            BeanUtils.populate(p,request.getParameterMap());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //更新数据
        ProductService service = new ProduceServiceImpl();
        int count = service.update(p);
        //重定向
        response.sendRedirect("/modelTest/pageServlet?currentPage="+currentPage);
    }
}
